async function initPage() {
  let { data: { data: { user_pic, username } } } = await getUserinfo()

  let userinfo = document.querySelectorAll('.userinfo')
  let htmlStr = ''
  if (user_pic) {
    htmlStr = `
    <img src=${user_pic} class="layui-nav-img" />
    <span id="welcome">欢迎 ${username}</span>
    `
  } else {
    htmlStr = `
    <span class="text-avatar">${username.charAt(0).toUpperCase()}</span>
    <span id="welcome">欢迎 ${username}</span>
    `
  }
  Array.from(userinfo).forEach(item => {
    item.innerHTML = htmlStr
  })
}
initPage()

let btnLogout = document.querySelector('#btnLogout')
btnLogout.addEventListener('click', function () {
  location.href = '/login.html'
  localStorage.removeItem('token')
})